package com.yang.service.adminimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yang.bean.MarketComment;
import com.yang.bean.MarketCommentExample;
import com.yang.bean.common.BasePageInfo;
import com.yang.bean.common.CommonData;
import com.yang.mapper.MarketCommentMapper;
import com.yang.service.admin.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CommentServiceImpl
 * @Description TODO
 * @Author zhangdongdong
 * @Date 2022/9/8 15:02
 * @Version 1.0
 */
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    MarketCommentMapper mapper;

    @Override
    public CommonData<MarketComment> list(BasePageInfo info, Integer userId, Integer valueId) {
        PageHelper.startPage(info.getPage(), info.getLimit());

        MarketCommentExample example = new MarketCommentExample();
        example.setOrderByClause(info.getSort() + " " + info.getOrder());

        MarketCommentExample.Criteria criteria = example.createCriteria();
        if (userId != null && !"".equals(userId)) {
            criteria.andUserIdEqualTo(userId);
        }
        if (valueId != null && !"".equals(valueId)) {
            criteria.andValueIdEqualTo(valueId);
        }

        List<MarketComment> list = mapper.selectByExample(example);

        PageInfo<MarketComment> pageInfo = new PageInfo<>(list);

        return CommonData.data(pageInfo);
    }

    @Override
    public void delete(MarketComment comment) {
        mapper.deleteByPrimaryKey(comment.getId());
    }
}
